﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MensUnoShop.Models.ViewModels.RegionViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	men'suno SHOP
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<div class="CART_CONTENT">
<img src="/Content/page_img/cart_content_top.gif" />
<div class="CART_TITLE">
<h1 class="TITLE_FAVORITE">購物車</h1>
<span class="FAVORITE_BT_CART"><a href="/market/c">檢視購物車</a></span>
<br class="CLEAR" />
</div>
<div class="CART_FORM">
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="104"><div align="center"></div></td>
    <td width="87"><div align="center"></div></td>
    <td><div align="left">商品<br />
      Item<br /></div></td>
    <td width="54"><div align="center">單價<br />
    Price</div></td>
    <td width="34"><div align="center">數量Quantity</div></td>
    <td width="58"><div align="center">金額小計Total price</div></td>
    <td width="52"><div align="center">刪除Delete</div></td>
  </tr>
  <%int i = 0; foreach (var item in Model.MEMBERFAVORITE)
    {%>
  <tr>    
    <input type="hidden" name="Mfid" id="Mfid_<%:i %>" value="<%:item.MFID %>" />
    <input type="hidden" name="Mkid" id="Mkid_<%:i %>" value="<%:item.MFMKGUID %>" />
    <input type="hidden" name="ProductId" id="ProductId_<%:i %>" value="<%:item.MFPRODUCTGUID %>" />
    <input type="hidden" name="SpecId" id="SpecId_<%:i %>" value="<%:item.MFSPECGUID %>" />
    <input type="hidden" name="Mktype" id="Mktype_<%:i %>" value="<%:item.MKTYPE %>" />
    <td>
        <div align="center">
        <%if (item.MFSTOCK > 0)
          {%>
            <input type="button" name="intoCart" id="intoCart" value="Add to cart" onclick="addShoppingCart(<%:i %>);" />
        <%}
          else
          { %>
            <%--<input type="button" name="button2" id="Submit1" value="貨到請通知我" />--%>
        <%} %>
        </div>
    </td>
    <td><div align="center"><img src="<%:item.MFPIC%>" width="75" height="75" /></div></td>
    <td valign="top"><%:item.MFMKSN%>-<%:item.MFPRODUCTTITLETAGID%>-<%:item.MFSPECTITLE%> <br /><%:item.MFMKTITLE%><br />
        <%if (item.MFSTOCK <= 0)
          {%><span class="PRODUCT3_HOT_POINT">缺貨中目前尚無庫存</span><%} %>
    </td>
    <td><div align="center">NT$<%:item.MFPRICE%></div></td>
    <td><div align="center"><input name="specamt" type="text" id="specamt_<%:i %>" value="1" size="2" /></div></td>
    <td><div align="center">NT$<%:item.MFPRICE%></div></td>
    <td><div align="center"><input type="button" id="delmyfavorite" class="delmyfavorite" value="Delete" onclick="delmyfavorite(<%:i %>);" /></div></td>
  </tr>
  <%i++;
    } %>
</table>

</div>
<br class="CLEAR" />
<img src="/Content/page_img/cart_content_bottom.gif" /></div>

<script type="text/javascript">
//$(document).ready(function () { $('.intoCart').click(addShoppingCart); $('.delmyfavorite').click(delmyfavorite); });
function addShoppingCart(no){
       if($("#specamt_"+no).val() > "0"){
           var jsonstring = {  "Mid": $("#Mkid_"+no).val(),
                               "ProductId": $("#ProductId_"+no).val(),
                               "SpecId": $("#SpecId_" + no).val(),
                               "AmountId": $("#specamt_"+no).val(),
                               "Mktype": $("#Mktype_" + no).val()
                             };
            $.ajax({
                type: "POST",
                traditional: true,
                url: "/api/stc",
                data: jsonstring,
                dataType: "json",
                success: function (data) {
                    if(data.code=="200"){
                        alert("已加入購物車!");
                    }
                    else
                        alert(data.response);
                } 
            });
        }
        else
            alert('請選擇數量');
    }

    function delmyfavorite(no)
    {
        var jsonstring = { "mfid": $("#Mfid_" + no).val() };
        $.ajax({
            type: "POST",
            traditional: true,
            url: "del_my_favorite",
            data: jsonstring,
            dataType: "json",
            success: function (data) {
                if(data.code=="200"){
                    alert("刪除成功!");location.reload();
                }
                else
                    alert("刪除失敗");location.reload();
            } 
        });
    }


    $(window).load(function(){
	    $('#pdintro img').each(function(i){
			$(this).removeAttr('width');
			$(this).removeAttr('height');
 
			//取得影像實際的長寬
			var imgW = $(this).width();
			var imgH = $(this).height();
 
			//計算縮放比例
			var w=500/imgW;
			var pre=1;
			if(w<1){
				pre=w;
			}else{
				pre=1;
			}
 
			if(pre!=1){
			    $(this).width(500);
			    $(this).height(imgH*pre);
                }
		});
    });
</script>
</asp:Content>
